package org.zzz.service.impl;

import org.apache.ibatis.session.SqlSession;
import org.zzz.entity.StudentCourse;
import org.zzz.mapper.StudentCourseMapper;
import org.zzz.service.StudentCourseService;
import org.zzz.utils.MybatisUtil;

import java.util.List;

/**
 * @Author ZZF
 * @Time 2021/04/20 22:46
 */
public class StudentCourseServiceImpl implements StudentCourseService {
    private StudentCourseMapper studentCourseMapper;

    {
//        SqlSession sqlSession = MybatisUtil.getSqlSession();
        studentCourseMapper = MybatisUtil.getMapper(StudentCourseMapper.class);
    }

    @Override
    public String listCourseNameBySid(String sid) {
        List<String> nameList = studentCourseMapper.listCourseNameBySid(sid);
        StringBuffer stringBuffer = new StringBuffer();
        String names = "";
        for (String s : nameList) {
            stringBuffer.append(s).append(", ");
        }
        if (stringBuffer.length()!=0){
            names = stringBuffer.toString().substring(0,stringBuffer.length()-2);
        }
        return names;
    }

    @Override
    public StudentCourse getStudentCourseBySid(String sid) {
        return studentCourseMapper.getSCBySid(sid);
    }

    @Override
    public boolean insertSC(StudentCourse studentCourse) {
        return studentCourseMapper.insertSC(studentCourse) > 0;
    }

    @Override
    public boolean updateSC(StudentCourse studentCourse) {
        return studentCourseMapper.updateSC(studentCourse) > 0;
    }

    @Override
    public boolean deleteSCById(String id) {
        return studentCourseMapper.deleteSCById(id) > 0;
    }
}
